<?php

use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Http\Request;
use Illuminate\Queue\Console\RetryCommand;
use Illuminate\Support\Facades\Auth;

class TravelersController extends BaseController {

	public function index()
	{
		return View::make('traveler/index');
	}
	
	public function add()
	{		
		return View::make('traveler/add', array( 'type' => Input::get('type') ));
	}
	
	public function handleAdd()
	{
		$post = Input::all();
		
		$traveler = new Traveler($post);
		
		$traveler->save();

		$this->send($post);
		
		return Redirect::action('TravelersController@index');
	}

	public function send($post)
	{
		
		if(!empty($post))
		{

			Mail::send('traveler/email' , $post, function ($message){
				$message->to('dmarques@lemontech.com.br')->subject('Notificação');
			});
			
		}
	}
	
	public function all()
	{
		$travelers = Traveler::paginate(10);
			
		return View::make('traveler/all', compact('travelers'));
	}
	
	public function info(Traveler $traveler)
	{
		return View::make('traveler/info', compact('traveler'));
	}
	
	public function search()
	{
		$search = Input::get('search');
		
		$travelers = Traveler::where('name', 'LIKE', '%' . $search . '%')->paginate(10);;
		
		return View::make('traveler/all', compact('travelers'));
		
	}
	
	public function status(Traveler $traveler)
	{
		$traveler->status = 0;
		$traveler->save();
		
		return Redirect::action('TravelersController@all');
	}
	
}
